package model;

import java.security.InvalidParameterException;
import java.util.EnumMap;

public class ChessBoard
{
    EnumMap<File, Cell[]> _board;
    
    public ChessBoard()
    {
        _board = new EnumMap<File, Cell[]>(File.class);

        for(File file : File.values())
        {
            _board.put(file, createCells(file));
        }
    }
    
    public Cell getCell(File file, int rank) throws InvalidParameterException
    {        
        return _board.get(file)[Rank.GetValue(rank)];
    }
    
    private Cell[] createCells(File file)
    {
        int[] ranks = Rank.GetRanks();
        Cell[] cells = new Cell[ranks.length];
        
        for(int rank : ranks)
        {
            cells[Rank.GetValue(rank)] = new Cell(file, rank).setChessBoard(this);
        }
        
        return cells;
    }
}
